import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from '@/views/index/index.vue'
import Login from '@/views/login.vue';
import { deviceList,user,customer,systemManage } from './routerList/index.js';
import storages from '@/until/localStorage.js';
import { findPathInArray } from './forFun.js';
import store from '@/store' 

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'login',
    component: Login
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login.vue')
  },
  {
    path: '/tips',
    name: 'tips',
    component: () => import('@/views/tips.vue')
  },
  {
    path: '/fromePage',
    name: 'fromePage',
    component: () => import('@/views/fromePage.vue')
  },
  {
    path: '/statuspage',
    name: 'statuspage',
    component: () => import('@/views/statuspage.vue')
  },
  {
    // 会匹配所有路径
    path: '*',
    name: '404',
    component: () => import('@/views/404/404.vue')
  },
  {
    path: '/index',
    name: 'index',
    component: Index,
    children: [
      {
        path: '/panelIndex',
        name: 'panelIndex',
        component: () => import('@/views/index/panelIndex.vue'),
        meta: {
          title: '首页'
        }
      },
      {
        path: '/userDetails',
        name: 'userDetails',
        component: () => import('@/views/index/userDetails.vue'),
        meta: {
          title: '用户详情'
        }
      }
    ]
  },
  ...deviceList,
  ...user,
  ...customer,
  ...systemManage
]
const originalPush = VueRouter.prototype.push
// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => {
    if (err.name !== 'NavigationDuplicated') {
      console.error(err)
    }
  })
}
const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})
export default router
